import {
  createRouter,
  createWebHashHistory,
  type RouteRecordRaw,
} from "vue-router";

import type { App } from "vue";
export const Layout = () => import("@/layout/index.vue");

export const constantRoutes: RouteRecordRaw[] = [
  // {
  //   path: "/dashboard",
  //   name: "/",
  //   component: Layout,
  //   meta: {
  //     title: "首页",
  //     showMenu: true,
  //   },
  //   children: [
  //     {
  //       path: "",
  //       component: () => import("@/views/dashboard/index.vue"),
  //       name: "Dashboard",
  //       meta: {
  //         showMenu: true,
  //         title: "dashboard",
  //         icon: "homepage",
  //       },
  //     },
  //   ]
  // },
  {
    path: "/login",
    name: "Login",
    meta: {
      title: "登录页",
    },
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/:catchAll(.*)",
    name: "error",
    component: () => import("@/views/error/404.vue"),
  },
  // 测试
  {
    path: "/Pinia",
    name: "Pinia",
    component: () => import("@/views/test/pinia.vue"),
  },
  // demo：主机终端器
  {
    path: "/hostTerminal",
    name: "hostTerminal",
    component: Layout,
    // component: () => import("@/views/test/pinia.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  scrollBehavior: () => ({ left: 0, top: 0 }), // 刷新时，滚动条位置还原
});

// 全局注册 router
export function setupRouter(app: App<Element>) {
  app.use(router);
}

export default router;
